﻿namespace HelperLibrary;

/// <summary>
/// Specifies a description for a property or event.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public class Description2Attribute : Attribute
{
    /// <summary>
    /// Specifies the default value for the <see cref='System.ComponentModel.Description2Attribute'/>,
    /// which is an empty string (""). This <see langword='static'/> field is read-only.
    /// </summary>
    public static readonly Description2Attribute Default = new Description2Attribute();

    public Description2Attribute() : this(string.Empty)
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref='System.ComponentModel.DescriptionAttribute'/> class.
    /// </summary>
    public Description2Attribute(string description)
    {
        DescriptionValue = description;
    }

    /// <summary>
    /// Gets the description stored in this attribute.
    /// </summary>
    public virtual string Description => DescriptionValue;

    /// <summary>
    /// Read/Write property that directly modifies the string stored in the description
    /// attribute. The default implementation of the <see cref="Description"/> property
    /// simply returns this value.
    /// </summary>
    protected string DescriptionValue { get; set; }

    public override bool Equals([NotNullWhen(true)] object? obj) =>
        obj is Description2Attribute other && other.Description == Description;

    public override int GetHashCode() => Description?.GetHashCode() ?? 0;

    public override bool IsDefaultAttribute() => Equals(Default);
}
